/*     */ package com.zimbra.cs.dav.service.method;
/*     */ 
/*     */ import com.zimbra.common.util.Pair;
/*     */ import com.zimbra.cs.dav.DavContext;
/*     */ import com.zimbra.cs.dav.DavContext.RequestProp;
/*     */ import com.zimbra.cs.dav.DavException;
/*     */ import com.zimbra.cs.dav.property.ResourceTypeProperty;
/*     */ import com.zimbra.cs.dav.resource.UrlNamespace;
/*     */ import com.zimbra.cs.dav.service.DavMethod;
/*     */ import com.zimbra.cs.dav.service.DavResponse;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import java.io.IOException;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import org.dom4j.Document;
/*     */ import org.dom4j.Element;
/*     */ import org.dom4j.QName;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class MkCol
/*     */   extends DavMethod
/*     */ {
/*     */   public static final String MKCOL = "MKCOL";
/*     */   
/*     */   public String getName()
/*     */   {
/*  49 */     return "MKCOL";
/*     */   }
/*     */   
/*     */   public void handle(DavContext ctxt) throws DavException, IOException {
/*  53 */     String user = ctxt.getUser();
/*  54 */     String name = ctxt.getItem();
/*     */     
/*  56 */     if ((user == null) || (name == null)) {
/*  57 */       throw new DavException("invalid uri", 406, null);
/*     */     }
/*  59 */     com.zimbra.cs.dav.resource.Collection col = UrlNamespace.getCollectionAtUrl(ctxt, ctxt.getPath());
/*  60 */     Pair<List<Element>, List<Element>> elemPair = null;
/*  61 */     if (ctxt.hasRequestMessage()) {
/*  62 */       Document req = ctxt.getRequestMessage();
/*  63 */       Element top = req.getRootElement();
/*  64 */       if (!top.getName().equals("mkcol")) {
/*  65 */         throw new DavException("body " + top.getName() + " not allowed in MKCOL", 400, null);
/*     */       }
/*     */       
/*  68 */       elemPair = PropPatch.getSetsAndRemoves(top, true, "MKCOL");
/*     */     }
/*  70 */     if (elemPair == null) {
/*  71 */       col.mkCol(ctxt, name);
/*  72 */       ctxt.setStatus(201);
/*     */     } else {
/*  74 */       Element resourcetypeElem = null;
/*  75 */       MailItem.Type view = null;
/*  76 */       List<Element> set = (List)elemPair.getFirst();
/*  77 */       Iterator<Element> setIter = set.iterator();
/*  78 */       while (setIter.hasNext()) {
/*  79 */         Element elem = (Element)setIter.next();
/*  80 */         String propName = elem.getName();
/*  81 */         if (propName.equals("resourcetype")) {
/*  82 */           ResourceTypeProperty prop = new ResourceTypeProperty(elem);
/*  83 */           if (prop.isAddressBook()) {
/*  84 */             view = MailItem.Type.CONTACT;
/*  85 */           } else if (prop.isCalendar()) {
/*  86 */             view = MailItem.Type.APPOINTMENT;
/*  87 */           } else if (!prop.isCollection()) {
/*  88 */             throw new DavException("resourcetype must include collection for MKCOL", 400, null);
/*     */           }
/*     */           
/*  91 */           resourcetypeElem = elem;
/*  92 */           setIter.remove();
/*  93 */           break;
/*     */         }
/*     */       }
/*  96 */       col = col.mkCol(ctxt, name, view);
/*  97 */       Pair<List<Element>, List<QName>> pair = PropPatch.processSetsAndRemoves(ctxt, col, (List)elemPair.getFirst(), (List)elemPair.getSecond(), true);
/*     */       
/*  99 */       col.patchProperties(ctxt, (java.util.Collection)pair.getFirst(), (java.util.Collection)pair.getSecond());
/* 100 */       ctxt.getResponseProp().addProp(resourcetypeElem);
/* 101 */       ctxt.setStatus(201);
/* 102 */       DavResponse resp = ctxt.getDavResponse();
/* 103 */       resp.addResource(ctxt, col, ctxt.getResponseProp(), false);
/* 104 */       sendResponse(ctxt);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/dav/service/method/MkCol.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */